package lsl.leetCode.year2023.test0126;

import java.util.HashSet;
import java.util.Set;

public class test03 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("adcedaebchdbb"));
    }

    //滑动窗口
    public static int lengthOfLongestSubstring(String s) {
        //右指针
        int r = 0;
        //左指针
        int l = 0;
        int res = 0;
        HashSet<Character> set = new HashSet<>();
        while (r < s.length()) {
            //移动右指针
            char c = s.charAt(r++);
            //维护滑动窗口
            while (set.contains(c)) {
                //去掉窗口中重复的元素,移动左指针
                set.remove(s.charAt(l++));
            }
            //滑动窗口添加新元素
            set.add(c);
            res = Math.max(res, set.size());
        }
        return res;
    }
}




